/**
* @Author: zmx
* @Date: 2023/9/25
* @Description:
*/
<template>
  <div style="padding: 20px">
    <el-form :inline="true" :model="formInline">
      <el-form-item>
        <el-button type="primary" icon="el-icon-plus" @click="addPlan">新建一类作业项</el-button>
      </el-form-item>
      <el-form-item label="作业项名称">
        <el-input v-model="formInline.assignName" placeholder="作业项名称"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
        <el-button @click="reset">清空</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="tableData" style="width: 100%" :header-cell-style="{background:'#006175',color:'#fff'}" :row-class-name="tableRowClassName">
      <el-table-column label="序号" width="50">
        <template v-slot="scope">
          {{ scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column type="expand">
        <template v-slot="scope">
          <el-table :data="scope.row.subVOList" style="width: 100%" :show-header="false" :row-class-name="tableRowClassNameChild">
            <el-table-column label="序号" width="100"></el-table-column>
            <el-table-column prop="assignSubName" label="作业项名称"></el-table-column>
            <el-table-column prop="assignContentDesc" label="内容描述" :show-overflow-tooltip="true"></el-table-column>
            <el-table-column prop="assignDemandDesc" label="要求描述" :show-overflow-tooltip="true"></el-table-column>
            <el-table-column prop="remark" label="备注"></el-table-column>
            <el-table-column prop="isUsing" label="使用情况">
              <template v-slot="scope">
                {{ scope.row.isUsing == 0 ? '未使用' : '使用中' }}
              </template>
            </el-table-column>
            <el-table-column label="操作" width="300px">
              <template v-slot="scope">
                <el-button class="common-btn" @click="getEditorAssign(scope.row)">修改</el-button>
                <el-button class="delete-btn" @click="getAssignDelete(scope.row)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </template>
      </el-table-column>
      <el-table-column prop="assignName" label="作业项名称" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column label="内容描述" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column label="要求描述" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column label="备注" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column label="使用情况">
<!--        <template v-slot="row">-->
<!--          {{ row.isUsing == 0 ? '未使用' : '使用' }}-->
<!--        </template>-->
      </el-table-column>
      <el-table-column label="操作" width="300px">
        <template v-slot="scope">
          <el-button class="common-btn" @click="getEditor(scope.row)">修改</el-button>
          <el-button class="delete-btn" @click="getDelete(scope.row)">删除</el-button>
          <el-button class="common-btn" @click="getAddAssign(scope.row)">+ 子类</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      style="margin-top: 20px"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
      :page-size="pagination.pageSize"
      layout="total, sizes, pager, next, jumper"
      :total="pagination.total">
    </el-pagination>
    <addRiskDialog v-if="DialogComponentShow" :DialogComponentShow="DialogComponentShow" @closeDialog="closeDialog" :title="title" :row="row"></addRiskDialog>
    <addAssignDialog v-if="DialogAssignShow" :DialogAssignShow="DialogAssignShow" @closeDialog="closeDialogAssign" :title="titleAssign" :row="row"></addAssignDialog>
  </div>
</template>

<script>
import {getAssignDelete, getAssignQuery, getSubAssignDelete} from '../../api/inspection/inspection'
import { tableRowClassName,tableRowClassNameChild } from '../../components/tableStyle';
import addRiskDialog from "./addRiskDialog";
import addAssignDialog from "./addAssignDialog";
export default {
  components: {
    addRiskDialog,
    addAssignDialog
  },
  data() {
    return {
      option: [],
      tableData: [],
      tableRowClassName,
      tableRowClassNameChild,
      title: '',
      titleAssign:'',
      row:'',
      formInline: {
        assignName: ''
      },
      pagination: {
        pageNum: 1,
        pageSize: 10,
        total: 0
      },
      DialogComponentShow: false,
      DialogAssignShow:false,
      optionsList: [
        {
          name: '充电桩',
          value: '1'
        }
      ],
      options: [
        {
          name: '启用',
          value: '1'
        },
        {
          name: '未启用',
          value: '0'
        },
      ]
    };
  },
  mounted() {
    this.getInit()
  },
  methods: {
    _getPlanOpen(row,title){
      this.title = title
      this.DialogComponentShow = true
      this.row = row
    },
    //新增大类
    addPlan() {
      this._getPlanOpen('','新增')
    },
    //修改大类
    getEditor(row) {
      this._getPlanOpen(row,'修改')
    },
    _getOpen(row,title){
      this.titleAssign = title
      this.DialogAssignShow = true
      this.row = row
    },
    //子类编辑
    getEditorAssign(row) {
      this._getOpen(row,'修改')
    },
    //子类新增
    getAddAssign(row){
      this._getOpen(row,'添加')
    },
    handleSizeChange(val) {
      this.pagination.pageSize = val
      this.getInit()
    },
    handleCurrentChange(val) {
      this.pagination.pageNum = val
      this.getInit()
    },
    getDelete(row) {
      this.$confirm('是否删除大类, 是否继续?', '删除', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let params = {
          id: row.id
        }
        getAssignDelete(params).then((res) => {
          if(res.code===200){
            this.$message({
              message: '删除成功',
              type: 'success'
            });
            this.getInit()
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    getAssignDelete(row){
      this.$confirm('是否删除子类, 是否继续?', '删除', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let params = {
          id: row.id
        }
        getSubAssignDelete(params).then((res) => {
          if(res.code===200){
            this.$message({
              message: '删除成功',
              type: 'success'
            });
            this.getInit()
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    //关闭弹框
    closeDialog() {
      this.DialogComponentShow = false
      this.getInit()
    },
    // 子类
    cancel(){
      this.DialogComponentShow = false
      this.DialogAssignShow = false
    },
    //关闭弹框
    closeDialogAssign(){
      this.DialogAssignShow = false
      // this.getInit()
      // let params = {
      //   pageNum: this.pagination.pageNum,
      //   pageSize: this.pagination.pageSize,
      //   assignName: this.formInline.assignName
      // }
      // getAssignQuery(params).then((res) => {
      //   if (res) {
      //     this.tableData = res.data
      //     this.pagination.total = res.total
      //   }
      // })
    },
    //列表
    getInit() {
      let params = {
        pageNum: this.pagination.pageNum,
        pageSize: this.pagination.pageSize,
        assignName: this.formInline.assignName
      }
      getAssignQuery(params).then((res) => {
        if (res) {
          this.tableData = res.data
          this.pagination.total = res.total
        }
      })
    },
    onSubmit() {
     this.getInit()
    },
    //手动清空
    reset() {
      this.formInline.assignName = ''
      this.getInit()
    },
  }
};

</script>

<style scoped>
>>> .el-table{
  margin-top: 0!important;
}
</style>
